<template>
  <svg v-bind="$attrs" class="svg-icon" :style="getStyle" aria-hidden="true">
    <use :xlink:href="symbolId" />
  </svg>
</template>

<script setup lang="ts">
import { computed, type CSSProperties } from 'vue'

const props = defineProps({
  prefix: {
    type: String,
    default: 'svg-icon',
  },
  name: {
    type: String,
    required: true,
  },
  size: {
    type: [Number, String],
    default: 16,
  },
  style: {
    type: Object,
    default: () => ({}),
  },
})
const symbolId = computed(() => `#${props.prefix}-${props.name}`)
const getStyle = computed((): CSSProperties => {
  const { size, style } = props
  const s = `${size}`.replace('px', '').concat('px')
  return {
    width: s,
    height: s,
    ...style,
  }
})
</script>

<style>
.svg-icon {
  overflow: hidden;
  fill: currentcolor;
  vertical-align: -0.15em;
}
</style>
